package com.gorkr;

import org.junit.jupiter.api.Test;

/**
 *
 *
 * @author gorkr
 * @date 2022/07/25 22:34
 **/
public class E88MergeSortedArray {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        while (m>0||n>0){

            int a = m-1>=0?nums1[m-1]:Integer.MIN_VALUE;
            int b = n-1>=0?nums2[n-1]:Integer.MIN_VALUE;

            if(a >= b){
                nums1[m+n-1]=nums1[m-1];
                m--;
            }else {
                nums1[m+n-1]=nums2[n-1];
                n--;
            }
        }

    }

    @Test
    public void test(){
       int[] nums1 = {1,2,3,0,0,0}, nums2 = {2,5,6};
       int m = 3,  n = 3;
       merge(nums1,m,nums2,n);
        System.out.println(nums1);
    }
}
    